using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class TaiXeDAO
    {
        public static DataTable LayThongTinTaiXe()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTaiXe", null);
            return dt;
        }
        #region TimThongTinTaiXeTheoTen
        public static DataTable TimThongTinTaiXeTheoTen(string TenTaiXe)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@TenTaiXe", TenTaiXe));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTheoTenTaiXe", sqlParams);
            return dt;
        }
        public static bool KiemTraTimThongTinTaiXeTheoTen(string TenTaiXe)
        {
            bool result = false;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TenTaiXe", TenTaiXe));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTheoTenTaiXe", sqlParams);

                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        #region TimThongTinTaiXeTheoMaNhanVien
        public static DataTable TimThongTinTaiXeTheoMaNhanVien(string MaTaiXe)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@MaTaiXe", MaTaiXe));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTheoMaNhanVien", sqlParams);
            return dt;
        }
        public static bool KiemTraTimThongTinTaiXeTheoMaNhanVien(string MaTaiXe)
        {
            bool result = false;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaTaiXe", MaTaiXe));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTheoMaNhanVien", sqlParams);

                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        #region TimThongTinTaiXeTheoXeDangLai
        public static DataTable TimThongTinTaiXeTheoXeDangLai(string MaSoXe)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@MaSoXe", MaSoXe));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTheoXeDangLai", sqlParams);
            return dt;
        }
        public static bool KiemTraTimThongTinTaiXeTheoXeDangLai(string MaSoXe)
        {
            bool result = false;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaSoXe", MaSoXe));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinTheoXeDangLai", sqlParams);

                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion  
        #region KiemTraNhapTaiXe

        public static bool NhapTaiXe(TaiXeDTO taixe)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaTaiXe", taixe.MaTaiXe));
                sqlParams.Add(new SqlParameter("@TenNhanVien", taixe.TenNhanVien));
                sqlParams.Add(new SqlParameter("@DiaChi", taixe.DiaChi));
                sqlParams.Add(new SqlParameter("@SoNamKinhNghiem", taixe.SoNamKinhNghiem));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spInsertTaiXe", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public static bool KiemTraNhapTaiXe(String MaTaiXe)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaTaiXe", MaTaiXe));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spKiemTraNhapTaiXe", sqlParams);
                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
    }
}
